Telegram Group & Telegram Channel
Используйте dict.get() вместо dict[]

Есть несколько способов получения значений из словарей, и даже по такой теме разработчики часто спорят.

Многие получают значения по ключам через квадратные скобки, но если такого ключа нет, то будет вызвано исключение.

Поэтому мы считаем, что лучше использовать метод get у словарей. Его основной плюс заключается в том, что он принимает опциональный аргумент, отвечающий за значение по умолчанию.

Таким образом, если значение по ключу не найдено, то вернется дефолтное значение.

В итоге, мы убираем возможные ошибки в случае, если нужных ключей в словаре нет.

#python #dict



tg-me.com/python_academy/1990
Create:
Last Update:

Используйте dict.get() вместо dict[]

Есть несколько способов получения значений из словарей, и даже по такой теме разработчики часто спорят.

Многие получают значения по ключам через квадратные скобки, но если такого ключа нет, то будет вызвано исключение.

Поэтому мы считаем, что лучше использовать метод get у словарей. Его основной плюс заключается в том, что он принимает опциональный аргумент, отвечающий за значение по умолчанию.

Таким образом, если значение по ключу не найдено, то вернется дефолтное значение.

В итоге, мы убираем возможные ошибки в случае, если нужных ключей в словаре нет.

#python #dict

BY Python Academy




Share with your friend now:
tg-me.com/python_academy/1990

View MORE
Open in Telegram


Python Academy Telegram | DID YOU KNOW?

Date: |

Telegram auto-delete message, expiring invites, and more

elegram is updating its messaging app with options for auto-deleting messages, expiring invite links, and new unlimited groups, the company shared in a blog post. Much like Signal, Telegram received a burst of new users in the confusion over WhatsApp’s privacy policy and now the company is adopting features that were already part of its competitors’ apps, features which offer more security and privacy. Auto-deleting messages were already possible in Telegram’s encrypted Secret Chats, but this new update for iOS and Android adds the option to make messages disappear in any kind of chat. Auto-delete can be enabled inside of chats, and set to delete either 24 hours or seven days after messages are sent. Auto-delete won’t remove every message though; if a message was sent before the feature was turned on, it’ll stick around. Telegram’s competitors have had similar features: WhatsApp introduced a feature in 2020 and Signal has had disappearing messages since at least 2016.

The lead from Wall Street offers little clarity as the major averages opened lower on Friday and then bounced back and forth across the unchanged line, finally finishing mixed and little changed.The Dow added 33.18 points or 0.10 percent to finish at 34,798.00, while the NASDAQ eased 4.54 points or 0.03 percent to close at 15,047.70 and the S&P 500 rose 6.50 points or 0.15 percent to end at 4,455.48. For the week, the Dow rose 0.6 percent, the NASDAQ added 0.1 percent and the S&P gained 0.5 percent.The lackluster performance on Wall Street came on uncertainty about the outlook for the markets following recent volatility.

Python Academy from tr


Telegram Python Academy
FROM USA